package com.pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

//对除自己以外的其他的Bean进行监控 -beanPostProcessor 比如修改值
public class TestBean implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("before: "+beanName);
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("after:"+beanName);
        if(bean instanceof Master) {
            Master master = (Master) bean;
            master.setName("after-小李");
            master.setAge(200);
        }
        return bean;
    }
}
